package net.xiaowenhou.demo.configure;

import org.springframework.cache.CacheManager;
import org.springframework.cache.annotation.CachingConfigurerSupport;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.cache.RedisCacheManager;
import org.springframework.data.redis.core.RedisTemplate;

@Configuration
@EnableCaching
public class ReidsConfig extends CachingConfigurerSupport{

  /*  @Override
    @Bean
    public org.springframework.cache.interceptor.KeyGenerator keyGenerator(){
        return new KeyGenerator(){

            @Override
            public Object generate(Object targer, Method method, Object... params){
                StringBuilder sb = new StringBuilder();
                sb.append(targer.getClass().getName());
                sb.append(method.getName());
                for (Object obj: params){
                    sb.append(obj.toString());
                }
                return sb.toString();
            }
        };
    }
*/
    @Bean
    public CacheManager cacheManager(RedisTemplate redisTemplate){
        RedisCacheManager redisCacheManager = new RedisCacheManager(redisTemplate);

        return redisCacheManager;
    }
}
